import Vue from 'vue'
import VueRouter from 'vue-router'
// import MobileHome from '../views/mobile/Home.vue'
// import PcHome from '../views/pc/Home.vue'
import Cookie from 'vue-cookies'
import Store from '../store'
import i18n from '../utils/i18n.js'
import {
	Message
} from 'element-ui';
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject)
		return originalPush.call(this, location, onResolve, onReject);
	return originalPush.call(this, location).catch((err) => err);
}

Vue.use(VueRouter)

const routes = [{
	path: '/pc/Home',
	alias: '/',
	name: '/pc/Home',
	component: () => import('../views/pc/Home.vue'),
}, {
	path: '/mobile/home',
	name: '/mobile/home',
	component: () => import('../views/mobile/Home.vue'),
	children: [{
		path: '/mobile/BettingRecord', 
		name: 'bettingRecord',
		component: () => import('../views/mobile/bettingRecord.vue'), //投注记录
	}],
}, {
	path: '/mobile/login',
	name: '/mobile/login',
	component: () => import('../views/mobile/login/index.vue'), //登录,
}, {
	path: '/mobile/register',
	name: '/mobile/register',
	component: () => import('../views/mobile/login/register.vue'), //注册,
}, {
	path: '/mobile/resetPassword',
	name: '/mobile/resetPassword',
	component: () => import('../views/mobile/login/forgot.vue'), //忘记密码
}, {
	path: '/mobile/Deposit',
	name: '/mobile/Deposit',
	component: () => import('../views/mobile/deposit.vue'), //存款
}, {
	path: '/mobile/setPassword',
	name: '/mobile/setPassword',
	component: () => import('../views/mobile/login/setPassword.vue'), //修改密码
}]



const router = new VueRouter({
	routes,
	mode: 'history'
})


// 游客能访问页面
const touristList = []

router.beforeEach((to, from, next) => {
	// console.log('to', to.path, from.path, to, from);
	let {
		token,
		language
	} = to.query
	if (token) {
		localStorage.setItem('TOKEN', token)
	}
	if(language){
		i18n.locale = language
		localStorage.setItem('lang', language)
	}
	if (window.innerWidth < 1024) {
		if (to.path.indexOf('mobile') == -1) {
			next('/mobile/home')
		} else {
			next()
		}
	} else {
		if (to.path.indexOf('mobile') != -1) {
			//移动端页面进入pc页面导航pc首页
			next(`/pc/Home`)
		} else {
			next()
		}
	}

})

export default router